<?php

namespace App\Http\Middleware;

use Closure;

use Auth;
use Guzzle\Http\Message\Response;



class User
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        if (Auth::check()){

            return $next($request);

        }else{
            if ($request->ajax()){
                //dd("dgag");
                //return redirect('/user/login');
               return response()->json(['status'=>0, 'message'=>'请登录']);

            }else{

                $returnUrl = $request->fullUrl();

                if ($returnUrl!=''){

                    return redirect('/user/login?return_url='.urlencode($returnUrl));


                }else{
                    return redirect('/user/login');

                }

            }
        }


    }
}
